package com.zj.sy.api;

import lombok.Data;

/**
 * @description: 服务接口 结果封装
 * @author: Carver Zhang
 * @create: 2020-11-24 16:52
 **/
@Data
public class R {

    private String msg;
    private Object data;
    private boolean success;

    private R(String msg, Object data, boolean success) {
        this.msg = msg;
        this.data = data;
        this.success = success;
    }

    public static R success(Object data) {
        return new R(PalSystemConstant.DEFAULT_SUCCESS_MESSAGE, data, Boolean.TRUE);
    }

    public static R success(String msg) {
        return new R(msg, null, Boolean.TRUE);
    }

    public static R fail(String msg) {
        return new R(msg, null, Boolean.FALSE);
    }

    public static R status(boolean flag) {
        return flag ? success(PalSystemConstant.DEFAULT_SUCCESS_MESSAGE) : fail(PalSystemConstant.DEFAULT_FAILURE_MESSAGE);
    }

    public static R execute(int exeResult) {
        return exeResult > 0 ? success(PalSystemConstant.DEFAULT_SUCCESS_MESSAGE) : fail(PalSystemConstant.DEFAULT_FAILURE_MESSAGE);
    }
}
